#make sure to change system to do with super() later
import items, enemies, actions, world

#defines the MapTile class
class MapTile:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    #EXPERIMENTORY####################
    #creates an inventory for map tiles
    def __init__(self):
    	self.inventory = []

    def print_inventory(self):
        for item in self.inventory:
            print(item, '\n')
	#EXPERIMENTORY End################
    def adjacent_moves(self):
        #Returns all move actions for adjacent tiles
        moves = []
        if world.tile_exists(self.x + 1, self.y):
            moves.append(actions.MoveEast())
        if world.tile_exists(self.x - 1, self.y):
            moves.append(actions.MoveWest())
        if world.tile_exists(self.x, self.y - 1):
            moves.append(actions.MoveNorth())
        if world.tile_exists(self.x, self.y + 1):
            moves.append(actions.MoveSouth())
        return moves
     
    def available_actions(self):
        #Returns all of the available actions in the room
        moves = self.adjacent_moves(self)
        moves.append(actions.ViewInventory())
     
        return moves

#defines the StartingRoom subclass of MapTile
class StartingRoom(MapTile):
    #CONTINUE DISCUSSION WITH LEAH HERE!!!
    def intro_text(self):
        return """
        You find yourself if a cave with a flickering torch on the wall.
        You can make out four paths, each equally as dark and foreboding.
        """
 
    def modify_player(self, player):
        #Room has no action on player
        pass

#Experimenting with implementing this into all tiles (see experimentory sections above)
#defines the LootRoom subclass of the superclass MapTile
class LootRoom(MapTile):
    pass
#    collected = {}
#    def __init__(self, x, y, item):
#        self.item = item
#        super().__init__(x, y)
# 	#adds an item to the player's inventory when entering the room
#    def add_loot(self, player):
#        if (self.x,self.y) not in collected:
#            collected[(seslf.x,self.y)] = True
#            player.inventory.append(self.item)
#            ## NOT YET COMPLETED
#
# 	
#    def modify_player(self, player):
#        self.add_loot(player)

#defines the EnemyRoom subclass
class EnemyRoom(MapTile):
    def __init__(self, x, y, enemy):
        self.enemy = enemy
        super().__init__(x, y)
 	#makes the enemy attack the player
    def modify_player(self, Player):
        if self.enemy.is_alive():
            Player.hp -= self.enemy.damage
            #prints the actions and effects in the room
            print("Enemy does {} damage. You have {} HP remaining.".format(self.enemy.damage, Player.hp))
    def available_actions(self):
        if self.enemy.is_alive():
            return [actions.Flee(tile=self), actions.Attack(enemy=self.enemy)]
        else:
            return self.adjacent_moves()

#defines the EmptyCavePath subclass
class EmptyCavePath(MapTile):
    def intro_text(self):
        return """
        Another unremarkable part of the cave. You must forge onwards.
        """
        self.inventory = []
        def modify_player(self, player):
        #Room has no action on player
            pass

#defines the GiantSpiderRoom subclass of the EnemyRoom superclass
class GiantSpiderRoom(EnemyRoom):
    def __init__(self, x, y, inventory):
        super().__init__(x, y, enemies.GiantSpider())
        self.inventory = [items.Dagger()]
 	#changes the intro text depending on whether the spider is alive
    def intro_text(self):
        if self.enemy.is_alive():
            return """
            A giant spider jumps down from its web in front of you!
            """
        else:
            return """
            The corpse of a dead spider rots on the ground.
            """
#creates the SnakePitRoom subclass of the EnemyRoom superclass
class SnakePitRoom(EnemyRoom):
    def __init__(self, x, y):
        super().__init__(x, y, enemies.Snakes())
 
    def intro_text(self):
        if self.enemy.is_alive():
            return """
            The floor opens to reveal a pit of writhing snakes!
            """
        else:
            return """
            You step into a pit filled with the bodies of dead snakes.
            """

#creates the FindDaggerRoom subclass of the LootRoom superclass
class FindDaggerRoom(LootRoom):
    def __init__(self, x, y):
        super().__init__(x, y, items.Dagger())
 
    def intro_text(self):
        return """
        You notice something shiny in the corner.
        """

#creates the Find5GoldRoom subclass of the LootRoom superclass
class Find5GoldRoom(LootRoom):
    def __init__(self, x, y):
        super().__init__(x, y, items.Gold(5))

    def intro_text(self):
        return """
        You see a grubby coin on the ground.
        You pick it up.
        It seems to be five gold!
        """
#defines the LeaveCaveRoom subclass of the MapTile superclass
class LeaveCaveRoom(MapTile):
    def intro_text(self):
        return """
        You see a bright light in the distance...
        ... it grows as you get closer! It's sunlight!
 
 
        Victory is yours!
        """
 
    def modify_player(self, player):
        player.victory = True